/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.mobiubiq.directory.client.data;

import java.util.Enumeration;
import java.util.Vector;
import org.kalmeo.kuix.core.KuixMIDlet;
import org.kalmeo.kuix.core.model.DataProvider;
import org.mobiubiq.directory.client.KuixClient;
import org.mobiubiq.directory.client.frame.Services;
import org.mobiubiq.directory.client.object.AbstractObject;
import org.mobiubiq.directory.service.DirectoryService;
import org.mobiubiq.directory.service.DirectoryServiceDao;
import org.mobiubiq.directory.service.NoServicesFoundException;
import org.mobiubiq.directory.service.ServiceException;

/**
 *
 * @author Marnix Renne
 */
public class ServicesDataProvider extends DataProvider {
    public static final String SERVICE = "service";
    
    public ServicesDataProvider(final AbstractObject object, final Services servicesFrame) {
        super();
        new Thread() {
            public void run() {
                try {
                    DirectoryServiceDao dao = DirectoryService.getInstance(KuixClient.getDefault());
                    Vector services = dao.findServices(object);
                    Enumeration e = services.elements();
                    while (e.hasMoreElements()) {
                        Service service = (Service) e.nextElement();
                        addItem(SERVICE, service);
                    }
                    servicesFrame.dataLoaded();
                } catch (NoServicesFoundException ex) {
                    servicesFrame.error(ex);
                } catch (ServiceException ex) {
                    servicesFrame.error(ex);
                }
            }
        }.start();
    }
}
